package org.hyf.inspur.LessonDesin.clear.count5;

import org.hyf.inspur.LessonDesin.clear.tools.TProperties;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

public class HighUserReducer extends Reducer<Text, IntWritable, NullWritable,Text> {
    protected void reduce(Text key, Iterable<IntWritable> values,
                          Reducer<Text, IntWritable, NullWritable,Text>.Context context)
            throws IOException, InterruptedException {
        Iterator<IntWritable> it=values.iterator();
        int count=0;
        System.out.println("+++++++++++++++++");
        while(it.hasNext()){
            System.out.println("键的值为:"+key);
            IntWritable value=it.next();
            int num=value.get();
            count=count+num;
        }
        String temp[]=key.toString().split(TProperties.getValue("fileoutsplit"));
        String user=temp[0] + "|" + temp[1] + "|" + count + "|" + temp[2];
        //System.out.println("+++++++++++");
        System.out.println(key +" count="+count);
        //context.write(new Text(key), new IntWritable(count));
        System.out.println(user);
        System.out.println("___________");
        context.write(NullWritable.get(), new Text(user));
    }
}
